package com.doit.spark.day05

import com.alibaba.fastjson.JSON

import scala.io.Source

/**
 * @DATE 2022/1/8/10:30
 * @Author MDK
 * @Version 2021.2.2
 * */
object TestJson {
  def main(args: Array[String]): Unit = {
    val br = Source.fromFile("data/movie/movie.log")
    val lines = br.getLines()
    var res: (String, Integer) = null
    val res1: Iterator[Any] = lines.map(line => {
      try {
        val nObject = JSON.parseObject(line)
        val movie: String = nObject.getString("movie")
        val rate: Integer = nObject.getInteger("rate")
        res = (movie, rate)
      } catch {
        case e: Exception =>
      }
        res
    }).filter(_!=null)
    res1.foreach(println)
  }
}
